package com.util.common.sql;

public class SearchKey {
	
	private String value;
	private String key;
	
	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}
	public String keyRed(){
		return signKeyRed(this.key,this.value);
	}

	/**
	 * 将搜索值中的关键字标红
	 * @param resultValue
	 * @param searchKey
	 * @return
	 */
	public String signKeyRed(String resultValue , String searchKey){
		String newValue = "";
		if(resultValue == null || "".equals(resultValue)){
			return "";
		}
		if(searchKey == null || "".equals(searchKey)){
			return resultValue;
		}
		char[] result = resultValue.toCharArray();
		char[] key = searchKey.toCharArray();
		int flag = 0;//标记newValue中有几个字符串
		for(int i = 0;i<key.length;i++){
			for(int j = flag;j<result.length;j++){
				if(isEquals(key[i],result[j])){
					newValue += "<font color='#FF000'>"+result[j]+"</font>";
					flag++;
					break;
				}else{
					newValue += result[j];
					flag++;
				}
			}
		}
		//未添加的字符 加入
		newValue += resultValue.substring(flag);
		
		return newValue;
	}
	
	public boolean isEquals(char one,char two){
		String src = one + "";
		String tar = two + "";
		if(src.toLowerCase().equals(tar.toLowerCase())){
			return true;
		}else{
			return false;
		}
	}
	
	public static void main(String[] args){
		SearchKey sk = new SearchKey();
		String str = sk.signKeyRed("000123456df78", "2348");
		System.out.println(str);
	}
}
